/*
 *    Copyright (c) 2018-2025, lengleng All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * Neither the name of the pig4cloud.com developer nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 * @author 品讯科技
 */
package com.px.pa.modulars.circle.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.px.pa.modulars.circle.entity.CircleTestQuestions;
import com.px.pa.modulars.circle.entity.CircleTestQuestionsItem;
import com.px.pa.modulars.circle.mapper.CircleTestQuestionsMapper;
import com.px.pa.modulars.circle.service.CircleTestQuestionsItemService;
import com.px.pa.modulars.circle.service.CircleTestQuestionsService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.io.Serializable;
import java.util.List;

/**
 * 试题表
 *
 * @author 品讯科技
 * @date 2024-08
 */
@Service
public class CircleTestQuestionsServiceImpl extends ServiceImpl<CircleTestQuestionsMapper, CircleTestQuestions> implements CircleTestQuestionsService {


    @Resource
    private CircleTestQuestionsService circleTestQuestionsService;
    @Resource
    private CircleTestQuestionsMapper circleTestQuestionsMapper;
    @Resource
    private CircleTestQuestionsItemService circleTestQuestionsItemService;
    @Override
    public Integer getCountByexaminationPaper(Integer examinationPaper, Integer topic) {
      Integer count =  circleTestQuestionsService.count(new QueryWrapper<CircleTestQuestions>().eq("examination_paper",examinationPaper)
        .eq("topic",topic));

        return count;
    }

    @Override
    public List<CircleTestQuestions> getCircleTestQuestionsList(Integer examinationPaper, Integer num1, Integer num2, Integer num3) {

    List<CircleTestQuestions> circleTestQuestionsList = circleTestQuestionsMapper.getCircleTestQuestionsList(examinationPaper,num1,num2,num3);
        circleTestQuestionsList.forEach(circleTestQuestions -> {
         List<CircleTestQuestionsItem> circleTestQuestionsItemList = circleTestQuestionsItemService.getListByTestQuestions(circleTestQuestions.getId());
            circleTestQuestions.setCircleTestQuestionsItemList(circleTestQuestionsItemList);
        });
        return circleTestQuestionsList;
    }

    @Override
    public boolean saveOrUpdate(CircleTestQuestions entity) {
        return saveOrUpdate(entity);
    }

    @Override
    public  boolean save(CircleTestQuestions entity){
        return super.save(entity);
    }

    @Override
    public CircleTestQuestions getById(Serializable id){
        return super.getById(id);
    }

    @Override
    public CircleTestQuestions queryById(Integer id){
        CircleTestQuestions tq=this.getById(id);
        return tq;
    }

    @Override
    public CircleTestQuestions get(Integer id) {
        return circleTestQuestionsMapper.get(id);
    }

}
